namespace FinalProject.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ChargeCategories",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Stores",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 14),
                        Phone = c.String(nullable: false),
                        Address_Street1 = c.String(nullable: false, maxLength: 22),
                        Address_Street2 = c.String(),
                        Address_City = c.String(nullable: false, maxLength: 14),
                        Address_State = c.String(nullable: false, maxLength: 2),
                        Address_ZipCode = c.Int(nullable: false),
                        Address_Country = c.String(nullable: false, maxLength: 12),
                        CompanyId = c.Int(nullable: false),
                        ChargeCategoryId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Companies", t => t.CompanyId, cascadeDelete: true)
                .ForeignKey("dbo.ChargeCategories", t => t.ChargeCategoryId, cascadeDelete: true)
                .Index(t => t.CompanyId)
                .Index(t => t.ChargeCategoryId);
            
            CreateTable(
                "dbo.Companies",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 16),
                        Address_Street1 = c.String(nullable: false, maxLength: 22),
                        Address_Street2 = c.String(),
                        Address_City = c.String(nullable: false, maxLength: 14),
                        Address_State = c.String(nullable: false, maxLength: 2),
                        Address_ZipCode = c.Int(nullable: false),
                        Address_Country = c.String(nullable: false, maxLength: 12),
                        Logo = c.String(),
                        PhoneNumber1 = c.Int(nullable: false),
                        PhoneNumber2 = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserDetails",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        DateCreated = c.DateTime(nullable: false),
                        LastUpdated = c.DateTime(nullable: false),
                        CompanyId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Companies", t => t.CompanyId, cascadeDelete: true)
                .ForeignKey("dbo.Users", t => t.Id)
                .Index(t => t.CompanyId)
                .Index(t => t.Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Comment = c.String(),
                        CreationDate = c.DateTime(nullable: false),
                        Email = c.String(),
                        IsApproved = c.Boolean(nullable: false),
                        IsLockedOut = c.Boolean(nullable: false),
                        IsOnline = c.Boolean(nullable: false),
                        LastActivityDate = c.DateTime(),
                        LastLockoutDate = c.DateTime(),
                        LastLoginDate = c.DateTime(),
                        LastPasswordChangedDate = c.DateTime(),
                        Password = c.String(),
                        PasswordQuestion = c.String(),
                        PasswordAnswer = c.String(),
                        ProviderName = c.String(),
                        UserName = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserRoles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 20),
                        DateCreated = c.DateTime(nullable: false),
                        LastUpdated = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Clients",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        PersonName_FirstName = c.String(nullable: false, maxLength: 30),
                        PersonName_LastName = c.String(nullable: false, maxLength: 30),
                        PersonName_MiddleName = c.String(nullable: false, maxLength: 30),
                        Phone = c.String(nullable: false),
                        Created = c.DateTime(nullable: false),
                        LastEdited = c.DateTime(nullable: false),
                        LastAccessed = c.DateTime(nullable: false),
                        StoreId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Stores", t => t.StoreId, cascadeDelete: true)
                .Index(t => t.StoreId);
            
            CreateTable(
                "dbo.Tickets",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 16),
                        TicketBalance = c.Double(nullable: false),
                        ClientId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Clients", t => t.ClientId, cascadeDelete: true)
                .Index(t => t.ClientId);
            
            CreateTable(
                "dbo.TicketItems",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 16),
                        Price = c.Double(nullable: false),
                        TicketId = c.Int(nullable: false),
                        ItemId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Tickets", t => t.TicketId, cascadeDelete: true)
                .ForeignKey("dbo.Items", t => t.ItemId, cascadeDelete: true)
                .Index(t => t.TicketId)
                .Index(t => t.ItemId);
            
            CreateTable(
                "dbo.Items",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 12),
                        Price = c.Double(nullable: false),
                        ServiceTypeId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ServiceTypes", t => t.ServiceTypeId, cascadeDelete: true)
                .Index(t => t.ServiceTypeId);
            
            CreateTable(
                "dbo.ServiceTypes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 16),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ItemColors",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Color = c.String(nullable: false, maxLength: 12),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ItemTextures",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 12),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UsersUserRoles",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        UserRoleId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserId, t.UserRoleId })
                .ForeignKey("dbo.Users", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.UserRoles", t => t.UserRoleId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.UserRoleId);
            
            CreateTable(
                "dbo.TicketItemsColors",
                c => new
                    {
                        TicketItemId = c.Int(nullable: false),
                        ColorId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.TicketItemId, t.ColorId })
                .ForeignKey("dbo.TicketItems", t => t.TicketItemId, cascadeDelete: true)
                .ForeignKey("dbo.ItemColors", t => t.ColorId, cascadeDelete: true)
                .Index(t => t.TicketItemId)
                .Index(t => t.ColorId);
            
            CreateTable(
                "dbo.TicketItemsTextures",
                c => new
                    {
                        TicketItemId = c.Int(nullable: false),
                        TextureId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.TicketItemId, t.TextureId })
                .ForeignKey("dbo.TicketItems", t => t.TicketItemId, cascadeDelete: true)
                .ForeignKey("dbo.ItemTextures", t => t.TextureId, cascadeDelete: true)
                .Index(t => t.TicketItemId)
                .Index(t => t.TextureId);
            
            CreateTable(
                "dbo.ChargeCategoriesServiceTypes",
                c => new
                    {
                        ChargeCategoryId = c.Int(nullable: false),
                        ServiceTypeId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.ChargeCategoryId, t.ServiceTypeId })
                .ForeignKey("dbo.ChargeCategories", t => t.ChargeCategoryId, cascadeDelete: true)
                .ForeignKey("dbo.ServiceTypes", t => t.ServiceTypeId, cascadeDelete: true)
                .Index(t => t.ChargeCategoryId)
                .Index(t => t.ServiceTypeId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.ChargeCategoriesServiceTypes", new[] { "ServiceTypeId" });
            DropIndex("dbo.ChargeCategoriesServiceTypes", new[] { "ChargeCategoryId" });
            DropIndex("dbo.TicketItemsTextures", new[] { "TextureId" });
            DropIndex("dbo.TicketItemsTextures", new[] { "TicketItemId" });
            DropIndex("dbo.TicketItemsColors", new[] { "ColorId" });
            DropIndex("dbo.TicketItemsColors", new[] { "TicketItemId" });
            DropIndex("dbo.UsersUserRoles", new[] { "UserRoleId" });
            DropIndex("dbo.UsersUserRoles", new[] { "UserId" });
            DropIndex("dbo.Items", new[] { "ServiceTypeId" });
            DropIndex("dbo.TicketItems", new[] { "ItemId" });
            DropIndex("dbo.TicketItems", new[] { "TicketId" });
            DropIndex("dbo.Tickets", new[] { "ClientId" });
            DropIndex("dbo.Clients", new[] { "StoreId" });
            DropIndex("dbo.UserDetails", new[] { "Id" });
            DropIndex("dbo.UserDetails", new[] { "CompanyId" });
            DropIndex("dbo.Stores", new[] { "ChargeCategoryId" });
            DropIndex("dbo.Stores", new[] { "CompanyId" });
            DropForeignKey("dbo.ChargeCategoriesServiceTypes", "ServiceTypeId", "dbo.ServiceTypes");
            DropForeignKey("dbo.ChargeCategoriesServiceTypes", "ChargeCategoryId", "dbo.ChargeCategories");
            DropForeignKey("dbo.TicketItemsTextures", "TextureId", "dbo.ItemTextures");
            DropForeignKey("dbo.TicketItemsTextures", "TicketItemId", "dbo.TicketItems");
            DropForeignKey("dbo.TicketItemsColors", "ColorId", "dbo.ItemColors");
            DropForeignKey("dbo.TicketItemsColors", "TicketItemId", "dbo.TicketItems");
            DropForeignKey("dbo.UsersUserRoles", "UserRoleId", "dbo.UserRoles");
            DropForeignKey("dbo.UsersUserRoles", "UserId", "dbo.Users");
            DropForeignKey("dbo.Items", "ServiceTypeId", "dbo.ServiceTypes");
            DropForeignKey("dbo.TicketItems", "ItemId", "dbo.Items");
            DropForeignKey("dbo.TicketItems", "TicketId", "dbo.Tickets");
            DropForeignKey("dbo.Tickets", "ClientId", "dbo.Clients");
            DropForeignKey("dbo.Clients", "StoreId", "dbo.Stores");
            DropForeignKey("dbo.UserDetails", "Id", "dbo.Users");
            DropForeignKey("dbo.UserDetails", "CompanyId", "dbo.Companies");
            DropForeignKey("dbo.Stores", "ChargeCategoryId", "dbo.ChargeCategories");
            DropForeignKey("dbo.Stores", "CompanyId", "dbo.Companies");
            DropTable("dbo.ChargeCategoriesServiceTypes");
            DropTable("dbo.TicketItemsTextures");
            DropTable("dbo.TicketItemsColors");
            DropTable("dbo.UsersUserRoles");
            DropTable("dbo.ItemTextures");
            DropTable("dbo.ItemColors");
            DropTable("dbo.ServiceTypes");
            DropTable("dbo.Items");
            DropTable("dbo.TicketItems");
            DropTable("dbo.Tickets");
            DropTable("dbo.Clients");
            DropTable("dbo.UserRoles");
            DropTable("dbo.Users");
            DropTable("dbo.UserDetails");
            DropTable("dbo.Companies");
            DropTable("dbo.Stores");
            DropTable("dbo.ChargeCategories");
        }
    }
}
